import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(),
  routes: [
    {
      path: '/',
      redirect: '/login'
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('@/views/MyLogin.vue')
    },
    {
      path: '/home',
      name: 'home',
      component: () => import('@/views/home/HomeView.vue'),
      children: [
        {
          path: 'index',
          name: 'index',
          component: () => import('@/views/home/IndexView.vue')
        },
        {
          path: 'about',
          name: 'about',
          component: () => import('@/views/home/AboutView.vue')
        },
        {
          path: 'my',
          name: 'my',
          component: () => import('@/views/home/MyView.vue')
        },
        {
          path: 'user',
          name: 'user',
          component: () => import('@/views/home/UserView.vue')
        }
      ]
    },

    {
      path: '/:catchAll(.*)',
      name: '404',
      component: () => import('@/views/404.vue')
    }
  ]
})

//luyou  拦截   是  双括号
// router.beforeEach((to, from, next) => {
//   if (to.path !== '/login' ) {
//     if (sessionStorage.getItem('token')) {
//       //判断出错  写成  localStorage
//       next()
//     } else {
//       next('/login')
//     }
//   } else {
//     next()
//   }
// })
export default router
